package lord.js.wods;

import handle.functions.SignUtil;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CoreServlet extends HttpServlet {
	private static final long serialVersionUID = 4890396138299131642L;
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		// four X
		// sign
        String sign = request.getParameter("signature");
        // suiji
        String echostr = request.getParameter("echostr");
        // time
        String timestamp = request.getParameter("timestamp");
        // suijishu
        String nonce = request.getParameter("nonce");
        System.out.println("MY "+sign+"|| "+echostr+"|| "+timestamp+"|| "+nonce);
        PrintWriter pw = response.getWriter();
        if(SignUtil.checkSign(sign, timestamp, nonce)){
        	pw.write(echostr);
        }
        pw.close();
        pw = null;
    }
	
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		PrintWriter pw = response.getWriter();
        {
        	//TODO Unkown Problem requrest.x===null
        	String xmlString = Deal.DO(request);
        	pw.print(xmlString);
        }
        pw.close();
        pw = null;
    }	
}
